#ifndef PLQDATABASE_H
#define PLQDATABASE_H

//Our includes
#include "plDatabase.h"

//Qt includes
#include <QList>

/*!
  \class plQDatabase

  This class is just a convienacne class for using qt library.  It allow to getAllObjects using a QList instead of std lists.
  */

class plQDatabase : public plDatabase
{
public:
    plQDatabase();

    ~plQDatabase() { }

    /*!
        See plDatabase::GetAllObjects() for details
      */
    template <class T>
            void GetAllObjects(QList<T*>& objects) {

        ReadOnly(true);

        //The select statement for all the
        T* object = new T();
        std::stringstream stream;
        stream << "SELECT id FROM " << object->_GetClassName();
        delete object;

        ReadOnly(false);

        //Where all the objects will be stored
        //std::list<T*>* objects = new std::list<T*>();

        //Go through all ids and create objects
        sqlite3_stmt* statement;
        int tableError = sqlite3_prepare_v2(Database, stream.str().c_str(), -1, &statement, NULL);

        //If sql prepar was okay
        if (tableError == SQLITE_OK) {
            //The current id value
            sqlite_int64 id;

            //Go through all the rows in the table
            while (sqlite3_step(statement) == SQLITE_ROW) {
                id = sqlite3_column_int64(statement, 0);
                //std::cout << "Id:" << id << std::endl;
                object = GetObject<T>(id);
                objects.push_back(object);
            } //while(sqlite3_step(statement) == SQLITE_ROW)
        }// end if(tableError == SQLITE_OK)

        sqlite3_finalize(statement);

    }
};

#endif // PLQDATABASE_H
